home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Panel Editor / Source / Panel.cpp < prev    next >
Encoding:
Text File  |  1995-12-08  |  7.1 KB  |  291 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Panel.h
  3.  
  4.     Contains:    Panel Classes Definition
  5.  
  6.     Written by:    Steve Smith
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- PanelEditor Includes --
  12.  
  13. #ifndef _PANEL_
  14. #include "Panel.h"
  15. #endif
  16.  
  17. #ifndef _LISTITEM_
  18. #include "ListItem.h"
  19. #endif
  20.  
  21. #ifndef _PANELEDITORDEF_
  22. #include "PanelEditorDef.h"
  23. #endif
  24.  
  25. #ifndef _PANELEDITORUTILS_
  26. #include "PanelEditorUtils.h"
  27. #endif
  28.  
  29. #ifndef _SAMPLECOLLECTIONS_
  30. #include "SampleCollections.h"
  31. #endif
  32.  
  33. // -- OpenDoc Includes --
  34.  
  35. #ifndef _ODTYPES_
  36. #include <ODTypes.h>
  37. #endif
  38.  
  39. #ifndef SOM_ODPart_xh
  40. #include <Part.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODFacet_xh
  44. #include <Facet.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODFrame_xh
  48. #include <Frame.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODFrameFacetIterator_xh
  52. #include <FrFaItr.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODDraft_xh
  56. #include <Draft.xh>
  57. #endif
  58.  
  59. // -- OpenDoc Utilities --
  60.  
  61. #ifndef _ODUTILS_
  62. #include <ODUtils.h>
  63. #endif
  64.  
  65. #ifndef _EXCEPT_
  66. #include <Except.h>
  67. #endif
  68.  
  69. #ifndef _TEMPOBJ_
  70. #include <TempObj.h>
  71. #endif
  72.  
  73. #ifndef _TEMPITER_
  74. #include <TempIter.h>
  75. #endif
  76.  
  77.  
  78. #pragma segment PanelEditorPanel
  79.  
  80. //==============================================================================
  81. // CPanel
  82. //==============================================================================
  83.  
  84. //------------------------------------------------------------------------------
  85. // Method:        Constructor
  86. //
  87. // Description:    This is the C++ class constructor.
  88. //------------------------------------------------------------------------------
  89.  
  90. CPanel::CPanel()
  91. {
  92.     fHasFrames = kODFalse;
  93. }
  94.  
  95. //------------------------------------------------------------------------------
  96. // Method:        InitPanel
  97. //
  98. // Description:    This is the C++ class constructor.
  99. //------------------------------------------------------------------------------
  100.  
  101. void CPanel::InitPanel()
  102. {
  103.     this->InitFrame();
  104. }
  105.  
  106. //------------------------------------------------------------------------------
  107. // Method:        Destructor
  108. //
  109. // Description:    This is the C++ class Destructor.
  110. //------------------------------------------------------------------------------
  111.  
  112. CPanel::~CPanel()
  113. {
  114.     ASSERT(fInited != kODFalse, kAssertionFailed);
  115. }
  116.  
  117. //------------------------------------------------------------------------------
  118. // Method:        CreateFrames
  119. //
  120. // Description:    This method is called in response to 
  121. //------------------------------------------------------------------------------
  122.  
  123. void CPanel::CreateFrames( Environment*    ev )
  124. {
  125.     inherited::CreateFrames(ev);
  126.     fHasFrames = kODTrue;
  127. }
  128.  
  129. //------------------------------------------------------------------------------
  130. // Method:        AddFrame
  131. //
  132. // Description:    This method is called in response to 
  133. //------------------------------------------------------------------------------
  134.  
  135. void CPanel::AddFrame( Environment* ev, ODFrame* containingFrame )
  136. {
  137.     ASSERT(fInited != kODFalse, kAssertionFailed);
  138.  
  139.     // We lazily create the frames and facets because we dont' know
  140.     // which part is in the "selection" until facets have been created.
  141.     fContainingFrames->Add(containingFrame);
  142.     
  143.     // But, if we've already created and displayed frames, then we need to
  144.     // add a new frame now.
  145.     if ( fHasFrames )
  146.         this->NewFrame(ev, containingFrame);
  147. }
  148.  
  149. //------------------------------------------------------------------------------
  150. // Method:        RemoveAll
  151. //
  152. // Description:    This method is called in response to 
  153. //------------------------------------------------------------------------------
  154.  
  155. ODFrame* CPanel::GetContainedFrame(Environment* ev, ODFrame* containingFrame)
  156. {
  157.     ODFrame* containedFrame = kODNULL;
  158.     
  159.     CFrameListIterator fiter(fFrames);
  160.     for ( ODFrame* frame=fiter.First();fiter.IsNotComplete();
  161.              frame=fiter.Next() )
  162.     {
  163.         TempODFrame parentFrame = frame->AcquireContainingFrame(ev);
  164.         if ( ODObjectsAreEqual(ev, parentFrame, containingFrame) )
  165.         {
  166.             containedFrame = frame;
  167.             break;
  168.         }
  169.     }
  170.     
  171.     return containedFrame;
  172. }
  173.  
  174. //------------------------------------------------------------------------------
  175. // Method:        RemoveAll
  176. //
  177. // Description:    This method is called in response to 
  178. //------------------------------------------------------------------------------
  179.  
  180. void CPanel::RemoveAll( Environment* ev )
  181. {
  182.     inherited::RemoveAll(ev);
  183.     fHasFrames = kODFalse;
  184. }
  185.  
  186.  
  187. //------------------------------------------------------------------------------
  188. // Method:        AddFacet
  189. //
  190. // Description:    This method is called when
  191. //------------------------------------------------------------------------------
  192.  
  193. void CPanel::AddFacet(Environment* ev, ODFacet* containingFacet)
  194. {
  195.     // Things are done lazily, so don't create a facet unless we
  196.     // really need to.
  197.  
  198.     if ( fHasFrames )
  199.         inherited::AddFacet(ev,containingFacet);
  200. }
  201.  
  202. //------------------------------------------------------------------------------
  203. // Method:        Draw
  204. //
  205. // Description:    This method is called in response to an update event.
  206. //------------------------------------------------------------------------------
  207.  
  208. void CPanel::Draw(Environment* ev, ODFacet* containingFacet)
  209. {
  210.     ODFrame* containingFrame = containingFacet->GetFrame(ev);
  211.     
  212.     // Leave space for the grow box and status line area.
  213.     ODUShort slHeight = (containingFrame->IsRoot(ev)) ? 15 : 0;
  214.     
  215.     Rect box;
  216.     GetQDFrameBounds(ev, containingFrame, &box);
  217.     
  218.     box.left = kPanelLeftEdge;
  219.     box.top += kPanelTopEdge;
  220.     box.right -= kPanelTopEdge;
  221.     box.bottom -= (kPanelTopEdge+slHeight);
  222.     
  223.     PenNormal();
  224.     FrameRect(&box);
  225. }
  226.  
  227. //------------------------------------------------------------------------------
  228. // Method:        GetFrameBounds
  229. //
  230. // Description:    This method is called in response to an update event.
  231. //------------------------------------------------------------------------------
  232.  
  233. ODRect CPanel::GetFrameBounds(Environment* ev, ODFrame* containingFrame)
  234. {
  235.     ODRect bounds;
  236.     TempODShape frameShape = containingFrame->AcquireFrameShape(ev, kODNULL);
  237.     frameShape->GetBoundingBox(ev, &bounds);
  238.     
  239.     // Leave space for the grow box and status line area.
  240.     ODUShort slHeight = (containingFrame->IsRoot(ev)) ? 15 : 0;
  241.         
  242.     bounds.top = 0;
  243.     bounds.left = 0;
  244.     bounds.bottom -= ff(2*kPanelTopEdge+2+slHeight);
  245.     bounds.right -= ff(kPanelLeftEdge+kPanelTopEdge+2);
  246.  
  247.     return bounds;
  248. }
  249.  
  250. //------------------------------------------------------------------------------
  251. // Method:        ChangeDisplayItem
  252. //
  253. // Description:    This method is called in response to 
  254. //------------------------------------------------------------------------------
  255.  
  256. void CPanel::ChangeDisplayItem(Environment* ev, CListItem* item)
  257. {
  258.     ASSERT(fInited != kODFalse, kAssertionFailed);
  259.  
  260.     ODReleaseObject(ev, fPartDisplayed);
  261.     fPartDisplayed = item->AcquirePart(ev);
  262.     
  263.     if ( fHasFrames == kODFalse )
  264.     {
  265.         this->CreateFrames(ev);
  266.         this->CreateFacets(ev);
  267.     }
  268.     
  269.     CFrameListIterator fiter(fFrames);
  270.     for ( ODFrame* frame=fiter.First();fiter.IsNotComplete();
  271.              frame=fiter.Next() )
  272.     {
  273.         // Reset the frame characteristics, so the new owner won't get confused.
  274.         TempODShape usedShape = ODCopyAndRelease(ev, frame->AcquireFrameShape(ev, kODNULL));
  275.         frame->ChangeUsedShape(ev, usedShape, kODNULL);
  276.         TempODFrameFacetIterator fiter(ev, frame);
  277.         for ( ODFacet* facet = fiter.First(); fiter.IsNotComplete();
  278.                 facet = fiter.Next() )
  279.         {
  280.             facet->ChangeActiveShape(ev, kODNULL, kODNULL);
  281.         }
  282.         
  283.         // Change owners.
  284.         frame->ChangePart(ev, fPartDisplayed);
  285.         frame->Invalidate(ev, kODNULL, kODNULL);
  286.     }    
  287. }
  288.  
  289.  
  290.  
  291.